package com.fresh.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fresh.dao.ExternalDataDao;
import com.fresh.dao.UserDao;
import com.fresh.entity.ExternalDataEntity;
import com.fresh.entity.UserEntity;
import com.fresh.service.IExternalDataService;
import com.fresh.utils.PageModel;


/**   
 * @Title: 123
 * @Description: 123
 * @author jeeweb
 * @date 2017-10-10 11:03:42
 * @version V1.0   
 *
 */
@Transactional(rollbackFor=RuntimeException.class)
@Service("externalDataService")
public class ExternalDataServiceImpl  implements IExternalDataService {

	@Resource
	private ExternalDataDao externalDataDao;
	
	@Resource
	private UserDao userDao;
		
	/**
	 * @param gmc
	 * @param 订单一览
	 */
	@Override
	public List<ExternalDataEntity> getExternalData(String shopId){
		return externalDataDao.getExternalData(shopId);	
	}

	/**
	 * @param 获取扩展总条数数据
	 * @param gmc
	 * @param mobile
	 * @return
	 */
	@Override
	public int getExternalDataCount(String userId) {
		
		return externalDataDao.getExternalDataCount(userId);
	}
	
	/**
	 * @param 根据商户编号得到员工信息
	 * @param gmc
	 * @param shopId 
	 * @return
	 */
	@Override
	public List<UserEntity> getUser(String shopId){
		
		return userDao.queryListByShopId(shopId);
		
	}

	/**
	 * @param 根据员工编号得到员工信息
	 * @param gmc
	 * @param shopId 
	 * @return
	 */
	@Override
	public UserEntity queryById(String id) {
		
		return userDao.queryById(id);
	}

	/**
	 * @param 根据订单编号获取信息
	 * @param gmc
	 * @param shopId 
	 * @return
	 */
	@Override
	public ExternalDataEntity queryExternal(String id) {
		// TODO Auto-generated method stub
		return externalDataDao.queryExternal(id);
	}

	/**
	 * @param 删除成功
	 * @param gmc
	 * @param userId 
	 * @return
	 */
	@Override
	public Boolean updateExternalByUserId(String userId) {
		// TODO Auto-generated method stub
		return externalDataDao.updateExternalByUserId(userId);
	}
	
	/**
	 * @param 删除
	 * @param gmc
	 * @param Id 
	 * @return
	 */
	@Override
	public Boolean updateUserById(String id) {
		return userDao.updateUserById(id);
	}
	
	/**
	 * 分页订单
	 */
	@Override
	public PageModel<ExternalDataEntity> queryPage(int currentPage, int size,String id) {
		//得到当前页数据的集合
		List<ExternalDataEntity> list = externalDataDao.queryPage((currentPage-1)*size, size, id);
		
		//封装pm
		PageModel<ExternalDataEntity> pm=new PageModel<ExternalDataEntity>();
		pm.setList(list);
		pm.setCurrentPage(currentPage);
		pm.setSize(size);
		
		int count=queryCount(id);
		pm.setSumCount(count);
		System.out.println(count+"====");
		pm.setSumPage(count);
		return pm;
	}
	
	@Override
	public int queryCount(String id) {
		return externalDataDao.queryCount(id);
	}

	
	/**
	 * 分页订单详细
	 */
	@Override
	public PageModel<ExternalDataEntity> queryOrderPage(int currentPage, int size,String id) {
		//得到当前页数据的集合
		List<ExternalDataEntity> list = externalDataDao.queryOrderPage((currentPage-1)*size, size, id);
		
		//封装pm
		PageModel<ExternalDataEntity> pm=new PageModel<ExternalDataEntity>();
		pm.setList(list);
		pm.setCurrentPage(currentPage);
		pm.setSize(size);
		
		int count=queryOrderCount(id);
		pm.setSumCount(count);
		pm.setSumPage(count);
		return pm;
	}

	@Override
	public int queryOrderCount(String id) {
		return externalDataDao.queryOrderCount(id);
	}
	
	

}
